********************************************************************************

* NFHS3 - Data creation and Empirical Analysis
* Data from the NFHS-3 can be obtained after registering for the Demographic and Health Survey Program (DHS - Round 5)

********************************************************************************

********************************************************************************
* Data creation
********************************************************************************

use "$ORIGINAL/IAHR52FL", clear 
rename hv001 v001 
rename hv002 v002 
sort v001 v002 
tempfile HH 
save `HH'

use "$ORIGINAL/IAIR52FL", clear 
sort v001 v002 
merge v001 v002 using `HH' 

keep if _merge == 3 
drop _merge 

********************************************************************************
* Rename relevant variables

rename v130 relig 
rename v012 agew 
rename v730 ageh
rename v010 yearb
rename v024 state 
rename s021 psu

********************************************************************************
* Treatment 

gen hindu1 = (relig != 2) 
replace hindu1 = . if relig == . 

gen christian = (relig == 3)
gen hindu = (relig == 1)
gen muslim = (relig == 2)

gen yy_1marr = int((s309c - 1) / 12) + 1900 
replace yy_1marr = int((s309c - 1) / 12) + 1900 if yy_1marr >= 100 

gen dowr_year = 1986
replace dowr_year = . if state == . 
gen dow_cohort = (dowr_year <= yy_1marr) 
replace dow_cohort = . if yy_1marr == . | dowr_year == . 

gen dowTreat = dow_cohort * hindu1 

* Early amended states and HSA states

gen dow_earlystate = (state == 2 | state == 3 | state == 6 | state == 10)
gen hsa_state =  (state == 32 | state == 28 | state == 33 | state == 29 | state == 27)

* HSA treatment
gen hsa_year = 1976 * (state == 32) + 1986 * (state == 28) + 1989 * (state == 33) + 1994 * (state == 27 | state == 29) + 2005 * (state != 32 & state != 28 & state != 33 & state != 29 & state != 27) 
replace hsa_year = . if state == . 
gen hsa_cohort = (hsa_year <= yy_1marr) 
replace hsa_cohort = . if yy_1marr == . | hsa_year == . 
gen hsaTreat = hsa_cohort * hindu1 

********************************************************************************
* Main Outcomes

* Decision Making

// what to cook
gen sayc = v743a==1|v743a==2 
replace sayc = . if v743a==9 | v743a==.

// large hh purchases
gen sayl = v743b==1|v743b==2 
replace sayl = . if v743b==9 | v743b==.

// small hh purchases	
gen says = v743c==1|v743c==2 
replace says = . if v743c==9 | v743c==.

gen saysc = says == 1 | sayc == 1

// hh purchases
gen sayp = sayl==1| says==1
replace sayl = . if sayl==. & says==.

gen husbandelsewhere = v504 !=1

// husband purchases
gen huss =  (v743f==1| v743f==2) 
replace huss = . if v743f==9| v743f==. | husbandelsewhere == 1

// healthcare decions
gen hdec =  v743a==1| v743a==2
replace hdec = . if v743a==9| v743a==.

// contraception decsions
gen cont = v632==1 | v632==3
replace cont=. if v632==9|v632==.

// healthcare decions + contraception decisions
gen hcdec = hdec==1| cont==1
replace hcdec = . if hdec==. & cont==.
replace hcdec = . if v213 == 1

// Women's decision power, conditional on > 0 (sum over all questons)
egen n_w_dec1 = rowtotal(sayl says huss hdec cont sayc), missing
gen n_w_dec = n_w_dec1 
replace n_w_dec = . if n_w_dec1 == 0

gen w_dec = (says == 1 | sayl == 1 | hcdec == 1)

* Husbands' restricts wife's autonomy

// Husband jealous if respondent talks to other men
gen h_beh1 = (d101a == 1)
replace h_beh1 = . if d101a > 1

// Husband accuses respondent of unfaithfulness
gen h_beh2 = (d101b == 1)
replace h_beh2 = . if d101b > 1

// Husband does not permit respondent to meet with friends
gen h_beh3 = (d101c == 1)
replace h_beh3 = . if d101c > 1

// Husband limits respondent's contact with family
gen h_beh4 = (d101d == 1)
replace h_beh4 = . if d101d > 1

// Husband insists to know where respondent is
gen h_beh5 = (d101e == 1)
replace h_beh5 = . if d101e > 1

// Controlling husband
gen hcontrol = (d102 > 0) 
replace hcontrol = . if d102 == .

// Control issues, conditional on > 0 (sum over all questions)
gen n_hcontrol = d102
replace n_hcontrol = . if hcontrol == 0


* Domestic violence

// Less-severe physical
gen viol_p1 = (d106 == 1)
replace viol_p1 = . if d106 > 2

// Severe physical
gen viol_p2 = (d107 == 1)
replace viol_p2 = . if d107 > 2

// Sexual
gen viol_s = (d108 == 1)
replace viol_s = . if d108 > 2

// Emotional
gen viol_e = (d104 == 1)
replace viol_e = . if d104 > 2

// Injuries caused by husband's actions
gen injuries = (d111 == 1)
replace injuries = . if d111 > 2

// Injuries caused by husband's actions (bruises)
gen inj1 = (d110a == 1)
replace inj1 = . if d110a > 2

// Injuries caused by husband's actions (sprains or dislocations)
gen inj2 = (d110b == 1)
replace inj2 = . if d110b > 2

// Injuries caused by husband's actions (wounds, broken bones or teeth)
gen inj3 = (d110c == 1)
replace inj3 = . if d110c > 2

// Injuries caused by husband's actions (burns)
gen inj4 = (d110d == 1)
replace inj4 = . if d110d > 2

// Domestic violence (sum over all questions)
egen n_viol = rowtotal(viol_p1 viol_p2 viol_s), missing

// Injuries, conditional on > 0 (sum over all questions)
egen n_inj = rowtotal(inj1 inj2 inj3 inj4), missing
replace n_inj = n_inj + n_viol


gen n_inj1 = n_inj
replace n_inj1 = 0 if injuries == 0


********************************************************************************
* Controls & Additional Outcomes

gen workw = ( v731 > 0 ) 
replace workw = . if v731 == 9 
gen workh = ( v705 > 1 ) 
replace workh = . if v705 > 10

gen educw = v133 
replace educw = . if v133 > 90 
gen collegew = 0
replace collegew = 1 if educw > 12
replace collegew = . if educw == . 

gen primary = v149>=2
replace primary= . if v149>8

gen secondary = v149>=4
replace secondary= . if v149>8


gen educh = v715 
replace educh = . if v715 > 90 
gen collegeh = 0
replace collegeh = 1 if educh > 12
replace collegeh = . if educh == . 
gen primaryh = (v701>=1)
replace primaryh = . if v701>3



gen hhsize = v136 
gen hhsize_sq = hhsize*hhsize 

gen scstbc = (s46<=3) 
replace scstbc = . if s46 == 8 | s46 == 9 

gen caste = sh46
replace caste = . if s46 == 8 | s46 == 9 

gen rural = ( hv025 == 2) 

gen sterilized = (v319>0)
replace sterilized = 0 if (v319>6)

egen sy = group(state yearb)
egen sry = group(state hindu1 yearb)

* Wealth and Assets

gen agrland_hec = sh60h
replace agrland_hec = . if sh60h > 900
gen irrland_hec = sh61h
replace irrland_hec = . if sh61h > 900

gen radio = (v120 == 1) 
replace radio = . if v120 ==9 | v120 == . 
gen tv = (v121 == 1) 
replace tv = . if v121 == 9 | v121 == . 
gen tel = (v153 == 1) 
replace tel = . if v122 == 9 | v122 == . 

gen asset1 = (radio == 1 | tv == 1 | tel == 1 )
replace asset1 = . if (radio == . | tv == . | tel == . )


gen bike = (v123 == 1) 
replace bike = . if v123 == 9 | v123 == . 
gen mbike = (v124 == 1) 
replace mbike = . if v124 ==9 | v124 == . 
gen car = (v125 ==1) 
replace car = . if v125 == 9 | v125 == . 

gen asset2 = (bike == 1 | mbike == 1 | car == 1 )
replace asset2 = . if (bike == . | mbike == . | car == . )


gen modern_roof =  (hv215 > 30)
replace  modern_roof  = . if hv215 >90
gen modern_cook = (v161<6)
replace modern_cook = . if v161 > 90

sum v191
gen wealth_index = (v191 - r(min))/(r(max)-r(min))

sum ssli
gen sl_index = (ssli - r(min))/(r(max)-r(min))

gen nkids_everborn = v201
gen nkids = v219
gen nkids_5 = v137
gen nkids_home = v202+v203
gen kids_home = nkids_home>0

gen nomorec = (v614 == v220) & v621 == 1


cap gen recentsex = (v536 == 1)
cap replace recentsex = . if v536 == 0 | v536 == 2 | v536>8

label var recentsex "Sex in Past 4 weeks"

* Marital sorting and matching

gen age_marr = v511
gen h_goodjob = (v705 == 2 | v705 == 3 | v705 == 4 | v705 == 5 | v705 == 6)
replace h_goodjob = . if workh == 0 | workh == .
gen educ_gap = educh - educw
gen age_gap = ageh - agew
gen drunk_often = (d114 == 1)
replace drunk_often = . if d114>8
gen h_earnless = (v746 != 2)
replace h_earnless = . if v746>5


gen woman_height = ha3_01/10
replace woman_height = . if woman_height>300

gen man_height =  hb3_01/10
replace man_height = . if man_height>300

gen height_diff = abs(woman_height - man_height)




* Reporting of violence

// Violence by others (not spouse)
gen viol_byothers = (d117a!=.)
replace viol_byothers = . if d117a == 2 | d117a == 9

// Violence in natal family 
gen viol_natal = (d121!=.)
replace viol_natal = . if d121 == 2 | d121 == 9

// Conditional on violence, has told anyone
gen told_anyone = (d128 == 1)
replace told_anyone = . if d128 >= 2

// Conditional on violence, has sought help from family
gen sought_help1 = (d119h == 1)
replace sought_help1 = . if d119h  >= 2

// Conditional on violence, has sought help from friends/network
gen sought_help2 = (d119j == 1 | d119k == 1 | d119u == 1 | d119x == 1 |d119xd == 1)
replace sought_help2 = . if (d119j  >= 2 | d119k >= 2 | d119u >= 2 | d119x >= 2 | d119xd >= 2)

// Conditional on violence, has sought help from institutions (police, religious leader, doctor etc.)
gen sought_help3 = (d119xb == 1 | d119xe == 1 | d119xf == 1 | d119xg == 1 | d119xh == 1)
replace sought_help3 = . if (d119xb >= 2 | d119xe >= 2 | d119xf >= 2 | d119xg >= 2 | d119xh >= 2)

* States

/*
1: jammu
2: himachal
3: punjab
5: uttaranchal
6: haryana
7: delhi
8: rajasthan
9: uttar
10: bihar
11: sikkim
12: arunachal
13: nagaland
14: manipur
15: mizoram
16: tripura
17: meghalaya
18: assam
19: west
20: jharkhand
21: orissa
22: chhattisgarh
23: madhya
24: gujarat
27: maharashtra
28: andhra
29: karnataka
30: goa
32: kerala
33: tamil
*/

gen north = (state == 1 | state == 2 | state == 3 | state == 9 | state == 5 | state == 6 | state == 7 | state == 8 | state == 23)
gen east = (state == 19 | state == 10 | state == 22 | state == 20 | state == 21 )
gen northeast = (state == 11 | state == 12 | state == 14 | state == 17 | state == 15 | state == 13 | state == 16 )
gen south = (state == 33 | state == 29 | state == 28 | state == 32 )
gen west = (state == 24 | state == 30 |state == 27 )


gen region = 1*north + 2*east + 3*northeast + 4*south + 5*west

* Woman's health

gen BMI = v445/100 
replace BMI = . if BMI >= 90 
gen lowBMI = (BMI<=18.5) 
replace lowBMI = . if BMI == . 
gen height = v438/10
replace height = . if height>=900 
sum height, d 
gen lowheight = ( height<r(p50))
replace lowheight = . if height == .
sum BMI, d 
gen lowBMI1 = (BMI<=r(p50)) 
replace lowBMI1 = . if BMI == . 

gen anemia_lev = v457 
replace anemia_lev = . if v457 == 9 | v457 == 8
gen anemic = (anemia_lev < 2) 
replace anemic = . if anemia_lev == . 
gen anemic_mod = (anemia_lev <= 2) 
replace anemic_mod = . if anemia_lev == . 
gen anemic_mild = (anemia_lev <= 3) 
replace anemic_mild = . if anemia_lev == .


*** Other measures of cultural norms: 

** number of female headed households in the state 
gen female_head = v151==2
bysort state: egen num_female_head_hh = total(female_head)

sum num_female_head_hh, d 

replace num_female_head_hh = (num_female_head_hh - r(min))/ (r(max) - r(min))

* Labels
label var dow_cohort "Post"
label var hindu1 "Non-Muslim"
label var dowTreat "Post $\times$ Non-Muslim"
label var hsa_cohort "HSAA"

label var w_dec "Any Decision"
label var n_w_dec "No. HH's Decisions"
label var sayl "Household Purchases"
label var hcdec "Own Health and Contraception"
label var huss "How to Spend Husband's Money"

label var injuries "Any Injury Caused by Husband"
label var n_inj "No. of Injuries Caused by Husband"
label var viol_p2 "Severe Physical Violence"
label var viol_p1 "Less Severe Violence"
label var viol_s "Sexual Violence"

label var injuries "Any Injury Caused by Husband"
label var n_inj "No. Injuries Caused by Husband"
label var viol_p2 "Severe Physical Violence"
label var viol_p1 "Less Severe Violence"
label var viol_s "Sexual Violence"

label var age_marr "Age at Marriage"
label var age_gap "Spousal Age Gap"
label var educ_gap "Spousal Education Gap" 
label var height_diff "Absolute Height Gap" 
label var workh "Husband is Employed" 
label var h_goodjob "Husband in White Collar Job"   
label var h_earnless "Husband Earns Less or Same" 
label var drunk_often "Husband Often Drunk"

label var educw "Years of Schooling"
label var primary "Primary School"
label var height "Height (cm)"
label var lowheight "Low Height"

label var viol_byothers "Violence by Others"
label var viol_natal "Violence in Natal Family"
label var told_anyone "Has Told Anyone About Violence"
label var sought_help1 "Has Sought Help From Family"
label var sought_help2 "Has Sought Help From Friends and Network"
label var sought_help3 "Has Sought Help From Police, Doctor, etc."

label var scstbc "SC/ST/OBC"
label var rural "Rural"
label var muslim "Muslim"
label var christian "Christian"
label var hindu "Hindu"
label var wealth_index "Wealth Index"
label var hhsize "Household Size"
label var workw "Employed in Past 12 Months"
label var nkids "No. Kids"
label var nkids_home "No. Kids at Home"
label var nomorec "Completed Fertility"
label var northeast "North East India"
label var south "South India"
label var north "North India"
label var east "East India"
label var west "West India"
label var num_female_head_hh "Normalized Number of Female Headed HH in the State"

********************************************************************************
* Sample selection
********************************************************************************

cap gen divsep = v501>=4
replace divsep = . if v501 == . | v501 == 3
bysort psu: egen divsep_psu = mean(divsep)
replace divsep_psu = divsep_psu * 100
keep if yy_1marr >= 1975 & yy_1marr <= 2000

* Drop Assam 
drop if state == 18

save "$OUTDATA/NFHS_sample_withdivorce.dta", replace 

* Keep married women
keep if v501 == 1 


save "$OUTDATA/NFHS_sample.dta", replace 
